﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class city_creating : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
                int no=int.Parse(Request["no"]);

                if (!this.IsPostBack)
                {

                    ctpDataContext db = new ctpDataContext();
                    ct_profile ct = db.ct_profiles.Single(p => p.no == no && p.language_no == 0);



                    this.Label1.Text = ct.title;
                    this.HyperLink2.NavigateUrl = "create_city_s.aspx?no=" + no;
                    this.Label3.Text = ct.country.Trim();

                    this.HyperLink3.Text = ct.user.nickname.Trim();
                    this.HyperLink3.NavigateUrl = "user_profile.aspx?no=" + ct.create_user_no.ToString();
                    //this.Label6.Text = ct.add_time.ToString();
                    if (ct.user.profile_picture != null)
                    {
                        this.Image2.ImageUrl = "user_imgs/1/" + ct.user.profile_picture.Trim();
                    }
                    else
                    {
                        this.Image2.Visible = false;
                    }

                    int continent =(int) ct.continent;
                    switch (continent)
                    {
                        case 0:
                            this.Label4.Text = "Asia";
                            break;
                        case 1:
                            this.Label4.Text = "America";
                            break;
                        case 2:
                            this.Label4.Text = "Africa";
                            break;
                        case 3:
                            this.Label4.Text = "Europe";
                            break;
                        case 4:
                            this.Label4.Text = "Oceania";
                            break;
                    }


                                


                    var data = from p in db.ct_s_profiles
                               join q in db.ct_s_types on p.type_no equals q.no
                               where p.valid==true && p.language_no == (int)Session["now_user_lang_no"] && p.ct_no == no && q.language_no == (int)Session["now_user_lang_no"]
                               orderby p.add_time
                               select new
                               {
                                   title=p.title,
                                   typetitle=q.title,
                                   no=p.no,
                                   ranking=p.ranking
                               };

                    this.GridView1.DataSource = data;
                    this.Label2.Text = data.Count().ToString();

                    ct.ct_s_amount = data.Count();
                    db.SubmitChanges();


                    this.DataBind();
                }
    }
}
